// 移动书签时触发
// chrome.bookmarks.onMoved.addListener(() => {
// })

// 接收内容区发送的数据
chrome.runtime.onMessage.addListener((request, sender, resp) => {
    // console.log("request ==> ", request.key);
    // console.log("sender ==> ", sender);
    // console.log("resp ==> ", resp);
    const lists = {
        // 'start_camera': start,
        // 'end_camera': end,
        // 'play_camera': play,
        // 'download_camera': null,
        'start_screen': record,
        'end_screen': stops,
        'download_screen': downloads
    }

    if (lists[request.key] && typeof lists[request.key] === 'function') {
        lists[request.key]()
        resp(1);
        return true;
    }

    resp(1);
});

// 向内容区域发送消息
// 先查询出处于活跃状态的窗口 active: true
function sendMessage(data) {
    console.log('v ==> ', data)
    chrome.tabs.query({
        active: true,
        currentWindow: true
    }, (tabs) => {
        console.log("tabs ====> ", tabs);
        chrome.tabs.sendMessage(tabs[0].id, data, (t) => {
            console.log("t==> ", t);
            return true
        });
    });
}